<?php
namespace app\wechat\controller;
use app\api\service\Message;
use think\View;

class WMessage extends WCommon
{
    // 用户消息首页
    public function index()
    {
        $type = input('param.type', 0);
        $this->assign('type', $type);
        $roles = ['member', 'repair', 'dealer', 'partner'];
        $param['member_role'] = $roles[$type];
        $param['member_id'] = session('member_id');
        $param['terrace'] = 'weixin';
        $data = Message::get_msg_unread_count($param);
        //dump($data);
        $this->assign('data', $data['data']);
        $urls = [url('member/index'), url('r_member/index'), url('d_member/index'), url('p_member/index')];
        $this->assign('url', $urls[$type]);
        return view();
    }

    // 消息列表
    public function msg_list() {
        $type = input('param.type', 0);
        $msg_type = input('param.msg_type', 0);
        if (request()->isAjax()) {
            $roles = ['member', 'repair', 'dealer', 'partner'];
            $param['member_role'] = $roles[$type];
            $param['member_id'] = session('member_id');
            $param['terrace'] = 'weixin';
            $param['msg_type'] = $msg_type;
            $data = Message::get_msg_list($param);
            if ($data['code'] == 200) {
                $view = new View();
                $view->assign('data', $data['data']['data']);
                $tpl = $view->fetch('w_message/msg_list_tpl');
                $data['tpl'] = $tpl;
            }
            return json($data);
        } else {
            $this->assign('type', $type);
            $this->assign('msg_type', $msg_type);
            return view();
        }
    }

    // 消息详情
    public function msg_info() {
        $id = input('param.id');
        $param = [
            'member_id' =>session('member_id'),
            'msg_id' => $id
        ];
        $data = Message::get_msg_info($param); // 获取详情
        //dump($data);
        $this->assign('data', $data['data']);
        return view();
    }
}
